package pl.iachoo.ctl.tabory.ui.base.masterdetail;

import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.forms.widgets.Form;
import org.eclipse.ui.forms.widgets.Section;

import pl.iachoo.ctl.tabory.ui.base.editor.AbstractEditorPart;
import pl.iachoo.ctl.tabory.ui.selection.ISelection;

public abstract class AbstractMasterDetailSection<T extends ISelection, MS extends AbstractMasterSectionPart<T>, DS extends AbstractDetailSectionPart<T>>
		extends AbstractEditorPart<T> {
	
	public AbstractMasterDetailSection() throws Exception {
		super();
	}

	protected MS masterSectionPart;
	protected DS detailSectionPart;

	@Override
	protected void initGui(Composite parent) {
		GridLayoutFactory.fillDefaults().numColumns(2).margins(5, 5)
				.applyTo(form.getBody());
		masterSectionPart = getMasterSection(form);
		detailSectionPart = getDetailSection(form);
		Section masterSection = masterSectionPart.getSection();
		Section detailSection = detailSectionPart.getSection();
		GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL)
				.grab(false, true).applyTo(masterSection);
		GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL)
				.grab(true, true).applyTo(detailSection);
	}

	protected abstract MS getMasterSection(Form parentForm);

	protected abstract DS getDetailSection(Form parentForm);

}
